package com.fattyCorps.common.packet.hero.component.prop.component;

import com.fattyCorps.common.enums.battle.ESkillType;
import com.fattyCorps.common.obj.config.SkillMould;
import com.fattyCorps.common.util.GameCfgUtils;
import com.fattyCorps.common.packet.hero.component.skill.HeroSkill;
import com.fattyCorps.common.packet.hero.component.prop.HeroProp;
import com.fattyCorps.common.packet.hero.component.prop.PropAdd;

import java.math.BigDecimal;
import java.util.List;

public class SkillProp extends ABasePropComponent {
    @Override
    public void onInit() {

    }

    @Override
    public void onUpdate() {
        // 获取所有技能
        HeroSkill skillComp = hero.getTrunk().getComponent(HeroSkill.class);
        for (SkillMould skillMould : skillComp.getPropSkills()) {
            // 此处加不加技能类型判断都可以，在下面行为也会对行为类型判断
            if (skillMould.getType().equals(ESkillType.Prop)) {
                List<Integer> bhvIds = GameCfgUtils.splitIdListStr(skillMould.getBehaviorIds());
                for (PropAdd propAdd : behaviorPropAdds(bhvIds)) {
                    switch (propAdd.calcType) {
                        case FixedValue:
                            owner.incProp(HeroProp.ECalcPropType.ExtraAdd, propAdd.propType, propAdd.value);
                            break;
                        case PerValue:
                            BigDecimal valB = new BigDecimal(propAdd.value);
                            owner.incProp(HeroProp.ECalcPropType.ExtraMult, propAdd.propType, valB.divide(BigDecimal.valueOf(100)).toString());
                            break;
                    }
                }
            }
        }
    }

    @Override
    public void onEvent(int e, Object[] objs) {

    }

}
